package com.atguigu.spring.ioc.config;

import com.atguigu.spring.ioc.datasource.TDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
public class DataSourceConfig {
    // 可以在application.properties文件中定义使用的环境标识
    @Profile({"dev-flag", "default"}) //  @Profile("环境标识"),环境标识激活时,才会加入如下组件
    @Bean
    public TDataSource dev() {
        TDataSource dev = new TDataSource();
        dev.setUrl("jdbc:mysql://localhost:3306/dev");
        dev.setUsername("dev_root");
        dev.setPassword("abc123456");
        return dev;
    }

    @Profile("prod-flag")
    @Bean
    public TDataSource production() {
        TDataSource prod = new TDataSource();
        prod.setUrl("jdbc:mysql://localhost:3306/prod");
        prod.setUsername("root");
        prod.setPassword("abc123456");
        return prod;
    }

    @Profile("test-flag")
    @Bean
    public TDataSource test() {
        TDataSource test = new TDataSource();
        test.setUrl("jdbc:mysql://localhost:3306/test");
        test.setUsername("test_root");
        test.setPassword("abc123456");
        return test;
    }
}
